Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: validation of bundled themes in build workflow #11627

Merged

Conversation

sarsapar1lla
Copy link
Contributor

Added xtask to validate bundled themes in order to detect issues at build time. Basically just loading all the themes are surfacing any warning logs which are emitted.

Main issue with the current implementation in the CI workflow is that it will cause builds on master to fail until the theme validation issues are addressed by their respective maintainers. Alternatively we could add a separate GitHub workflow which only triggers when the runtime/themes directory is edited but this felt like overkill in this instance.

Add: xtask for validating bundled themes
Update: build workflow to run theme validation on build

Closes #5709

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we refactor Theme::load to return a Vec of any warnings (so basically Result<(Theme, Vec<String>)>). The current callers of Theme::load can then log the warnings and the xtask can print them and error out.

@the-mikedavis
Copy link
Member

For the themes that currently fail to pass this we can comment out the offending keys and link to the issue. They're basically discarded while loading so commenting them out should be equivalent

@sarsapar1lla
Copy link
Contributor Author

sarsapar1lla commented Sep 4, 2024

Updated the implementation to explicitly return validation failures rather than use log captures. This involved adding a new public factory constructor on the Theme struct, Theme::from_keys, which allows for the creation of a theme from a toml map. This felt less intrusive than altering the return type of Loader.load plus allows the From<Value> and Deserialize impls for Theme to still work.

Please let me know if I've misunderstood what you were suggesting!

EDIT: I see now that we need to update the loader in order to correctly handle inherited styles and palette colours. Will update

@sarsapar1lla
Copy link
Contributor Author

I've updated the implementation to return both the theme and any validation failures from the Loader.load method and logged the failures at each call site. I've also updated the affected themes and commented out the invalid keys as per your suggestion.

The theme_check task now completes successfully and the warnings no longer appear in the logs when selecting themes such as emacs.

Let me know what you think @the-mikedavis

@@ -52,21 +52,24 @@ impl Loader {
}

/// Loads a theme searching directories in priority order.
pub fn load(&self, name: &str) -> Result<Theme> {
pub fn load(&self, name: &str) -> Result<(Theme, Vec<String>)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have many callers that need to handle the warnings let's create a load_with_warnings helper that has this function's body and then load can call that helper and log the warnings.

let (theme, warnings) = self.load_with_warnings(name)?;

for warning in warnings {
warn!("Theme '{}': {}", name, warning);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logging theme name along with warning

@sarsapar1lla
Copy link
Contributor Author

Introduced helper method as suggested. Now that the warnings are being logged in the same place, I updated the warning messages to include the theme name to make it clearer to users which theme is the source of the warning

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'm looking forward to this - I always pull down a theme PR and run it and look at the log and automating this step will be nice

@pascalkuthe pascalkuthe merged commit 82dd963 into helix-editor:master Sep 28, 2024
6 checks passed
plul pushed a commit to plul/helix that referenced this pull request Oct 13, 2024
* Add: xtask to check themes for validation warnings

* Update: tidied up runtime paths

* Update: test build workflow

* Update: address clippy lints

* Revert: only trigger workflow on push to master branch

* Add: Theme::from_keys factory method to construct theme from Toml keys

* Update: returning validation failures in Loader.load method

* Update: commented out invalid keys from affected themes

* Update: correct invalid keys so that valid styles still applied

* Update: include default and base16_default themes in check

* Update: renamed validation_failures to load_errors

* Update: introduce load_with_warnings helper function and centralise logging of theme warnings

* Update: use consistent naming throughout
@sarsapar1lla sarsapar1lla deleted the task/validate-themes-in-ci branch November 9, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants